package com.lrkj.smartservice.controller;

import java.util.List;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.smartservice.domain.PressInfo;
import com.lrkj.smartservice.service.IPressInfoService;

/**
 * 新闻管理Controller
 *
 * @author yajun_ren
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/smartservice/pressInfo")
public class PressInfoController extends BaseController
{
    @Autowired
    private IPressInfoService pressInfoService;

    /**
     * 查询新闻管理列表
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PressInfo pressInfo)
    {
        startPage();
        List<PressInfo> list = pressInfoService.selectPressInfoList(pressInfo);
        return getDataTable(list);
    }

    /**
     * 导出新闻管理列表
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:export')")
    @Log(title = "新闻管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PressInfo pressInfo)
    {
        List<PressInfo> list = pressInfoService.selectPressInfoList(pressInfo);
        ExcelUtil<PressInfo> util = new ExcelUtil<PressInfo>(PressInfo.class);
        return util.exportExcel(list, "pressInfo");
    }

    /**
     * 获取新闻管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:query')")
    @GetMapping(value = "/{pressInfoId}")
    public AjaxResult getInfo(@PathVariable("pressInfoId") String pressInfoId)
    {
        return AjaxResult.success(pressInfoService.selectPressInfoById(pressInfoId));
    }

    /**
     * 新增新闻管理
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:add')")
    @Log(title = "新闻管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PressInfo pressInfo)
    {
        return toAjax(pressInfoService.insertPressInfo(pressInfo));
    }

    /**
     * 修改新闻管理
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:edit')")
    @Log(title = "新闻管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PressInfo pressInfo)
    {
        return toAjax(pressInfoService.updatePressInfo(pressInfo));
    }

    /**
     * 删除新闻管理
     */
    @PreAuthorize("@ss.hasPermi('smartservice:pressInfo:remove')")
    @Log(title = "新闻管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pressInfoIds}")
    public AjaxResult remove(@PathVariable String[] pressInfoIds)
    {
        return toAjax(pressInfoService.deletePressInfoByIds(pressInfoIds));
    }
}
